Passed
Push — master ( 1b6984...937909 )
by Eduardo
02:28
created

$(ꞌ#swInputDomainꞌ).keyup   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
c 0
b 0
f 0
nc 2
dl 0
loc 9
rs 10
nop 1
1
var whois = require('../common/whoiswrapper.js'),
2
  parseRawData = require('../common/parse-raw-data.js');
3
4
window.$ = window.jQuery = require('jquery');
5
6
const {
7
  ipcRenderer
8
} = require('electron');
9
10
var singleWhois = {
11
  'input': {
12
    'domain': null
13
  },
14
  'results': null
15
}
16
17
// Single Whois, whois reply processing
18
ipcRenderer.on('sw:results', function(event, domainResults) {
19
  const {
20
    isDomainAvailable
21
  } = whois;
22
  var domainStatus, domainResultsJSON;
23
  //ipcRenderer.send('app:debug', "Whois domain reply:\n {0}".format(domainResults));
24
25
  domainResultsJSON = (function() {
26
    var result;
27
    if (typeof domainResults === 'object') {
28
      JSON.stringify(domainResults, null, 2);
29
      result = domainResults.map(function(data) {
30
        data.data = parseRawData(data.data);
31
        return data;
32
      });
33
    } else {
34
      result = parseRawData(domainResults);
35
    }
36
    return result;
37
  })();
38
39
  // Check domain status
40
  domainStatus = isDomainAvailable(domainResults);
41
42
  switch (domainStatus) {
43
    case 'querylimituniregistry':
44
    case 'error':
45
      $('#swMessageWhoisResults').text("Whois error: {0}\n{1}".format(domainStatus, domainResults));
46
      $('#swMessageError').removeClass('is-hidden');
47
      break;
48
    case 'unavailable':
49
    //console.log(domainResultsJSON);
50
      $('#swMessageUnavailable').removeClass('is-hidden');
51
      $('#swMessageWhoisResults').text(domainResults);
52
53
      $('#swTdDomain').attr('href', "http://" + domainResultsJSON['domainName'] || domainResultsJSON['domain']);
54
      $('#swTdDomain').text(domainResultsJSON['domainName'] || domainResultsJSON['domain']);
55
56
      $('#swTdUpdate').text(domainResultsJSON['updatedDate']);
57
      $('#swTdRegistrar').text(domainResultsJSON['registrar']);
58
      $('#swTdCreation').text(domainResultsJSON['creationDate'] || domainResultsJSON['createdDate'] || domainResultsJSON['created']);
59
      $('#swTdCompany').text(domainResultsJSON['registrantOrganization'] || domainResultsJSON['registrant']);
60
      $('#swTdExpiry').text(domainResultsJSON['registrarRegistrationExpirationDate'] || domainResultsJSON['expires'] || domainResultsJSON['Registry Expiry Date']);
61
      $('#swTableWhoisinfo.is-hidden').removeClass('is-hidden');
62
      break;
63
    case 'available':
64
      $('#swMessageWhoisResults').text(domainResults);
65
      $('#swMessageAvailable').removeClass('is-hidden');
66
      break;
67
    default:
68
      $('#swMessageWhoisResults').text("Whois default error\n{0}".format(domainResults));
69
      $('#swMessageError').removeClass('is-hidden');
70
      break;
71
  }
72
73
  $('#swSearchButtonSearch').removeClass('is-loading');
74
  $('#swSearchInputDomain').removeAttr('readonly');
75
76
});
77
78
// Simple Whois, trigger search by using [ENTER] key
79
$('#swSearchInputDomain').keyup(function(event) {
80
  // Cancel the default action, if needed
81
  event.preventDefault();
82
  // Number 13 is the "Enter" key on the keyboard
83
  if (event.keyCode === 13) {
84
    // Trigger the button element with a click
85
    $('#swSearchButtonSearch').click();
86
  }
87
});
88
89
// Trigger Whois lookup
90
$('#swSearchButtonSearch').click(function() {
91
  if ($(this).hasClass('is-loading')) {
92
    return true;
93
  }
94
  ipcRenderer.send('app:debug', "#swSearchButtonSearch was clicked");
95
96
  singleWhois.input.domain = $('#swSearchInputDomain').val();
97
98
  ipcRenderer.send('app:debug', "Looking up for {0}".format(singleWhois.input.domain));
99
100
  $('#swSearchButtonSearch').addClass('is-loading');
101
  $('#swSearchInputDomain').attr('readonly', '');
102
  $('.notification:not(.is-hidden)').addClass('is-hidden');
103
  $('#swTableWhoisinfo:not(.is-hidden)').addClass('is-hidden');
104
  tableReset();
105
  ipcRenderer.send("sw:lookup", singleWhois.input.domain);
106
  return undefined;
107
});
108
109
// Open simple whois model
110
$('.swMessageWhoisOpen').click(function() {
111
  ipcRenderer.send('app:debug', "Opening whois reply");
112
  $('#swMessageWhois').addClass('is-active');
113
});
114
115
// Close simple whois modal
116
$('#swMessageWhoisClose').click(function() {
117
  ipcRenderer.send('app:debug', "Closing whois reply");
118
  $('#swMessageWhois').removeClass('is-active');
119
});
120
121
// Reset registry table contents
122
function tableReset() {
123
  ipcRenderer.send('app:debug', "Resetting whois result table");
124
  $('#swTdDomain').attr('href', "#");
125
  $('#swTdDomain').text('n/a');
126
127
  $('#swTdUpdate').text('n/a');
128
  $('#swTdRegistrar').text('n/a');
129
  $('#swTdCreation').text('n/a');
130
  $('#swTdCompany').text('n/a');
131
  $('#swTdExpiry').text('n/a');
132
}
133